﻿@model ZSZ.AdminWeb.Models.Role.RoleEditGet
@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<form id="formData">
    <input type="hidden" name="id" value="@Model.Role.Id" />
    <div class="row cl">
        <label class="form-label col-3"><span class="c-red">*</span>角色名字：</label>
        <div class="formControls col-5">
            <input type="text" value="@Model.Role.Name" class="input-text" name="name" id="name" datatype="*1-50" nullmsg="角色名称不能为空" />
        </div>
        <div class="col-4"> </div>
    </div>
    <div class="row cl">
        @foreach (var perm in Model.QuanPer)
        {
            <div class="col-xs-12 col-sm-3">
                <input type="checkbox" id="PermissionIds_@perm.Id" checked="@Model.CheckPer.Any(s=>s.Id==perm.Id)" name="PermissionIds" value="@perm.Id" />
                <label for="PermissionIds_@perm.Id">@perm.Description</label>
            </div>
        }
    </div>
    <input type="button" value="修改" id="save" />
</form>

@section footerjs{
    <script src="~/js/Validform_v5.3.2.js"></script>
    <script type="text/javascript">
        $('#save').click(function () {
            if ($('#formData').Validform().check(false)) {
                var fromData = $('#formData').serializeArray();
                $.ajax({
                    url: '/Role/Edit',
                    data: fromData,
                    dataType: 'json',
                    type: 'post',
                    success: function (res) {
                        if (res.status == 'ok') {
                            parent.location.reload();
                        } else {
                            alert(res.errorMsg);
                        }
                    },
                    error: function () {
                        alert('网络请求错误');
                    }
                })
            }
        })
        $(function () {
            $('#formData').Validform({ tiptype: 2 });
        })
    </script>
}

